 package com.shanzhu.flower.service.impl;

import com.shanzhu.flower.dao.AnnouncementDao;
import com.shanzhu.flower.entity.Announcement;
import com.shanzhu.flower.service.AnnouncementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

/**
 * 公告Service实现类
 */
@Service
public class AnnouncementServiceImpl implements AnnouncementService {
    
    @Autowired
    private AnnouncementDao announcementDao;
    
    @Override
    public List<Announcement> getEnabledAnnouncements() {
        return announcementDao.selectEnabledAnnouncements();
    }
    
    @Override
    public List<Announcement> getAllAnnouncements() {
        return announcementDao.selectAllAnnouncements();
    }
    
    @Override
    public Announcement getById(Integer id) {
        return announcementDao.selectById(id);
    }
    
    @Override
    public boolean addAnnouncement(Announcement announcement) {
        // 设置默认状态为启用
        if (announcement.getStatus() == null) {
            announcement.setStatus(1);
        }
        return announcementDao.insert(announcement) > 0;
    }
    
    @Override
    public boolean updateAnnouncement(Announcement announcement) {
        return announcementDao.update(announcement) > 0;
    }
    
    @Override
    public boolean deleteAnnouncement(Integer id) {
        return announcementDao.deleteById(id) > 0;
    }
    
    @Override
    public boolean updateStatus(Integer id, Integer status) {
        return announcementDao.updateStatus(id, status) > 0;
    }
} 